package acceptance;

import presentation.UIPost ;
import presentation.UIThread ;
import domain.message.Post ;
import domain.message.Thread ;


/**
* implements methods when there is no application
* all hard coded tests according to what we want the application to do
*/

public class ProxyBridge implements IBridge
{


	/**
	 * to check if we can register the same username twice
	 */
	public boolean wasRegistered = false;



	public boolean addModaratorPrivileges(final long adminId,final String userName){
		if ((adminId!=1) || (userName.equals("mimi")))
		{
			return false;
		}
		else
		{
			return true;
		}
	}


	public UIPost addPost(final long threadId,final String msg,final long writerId){
		if ((msg.equals("hello this is a test"))&&(writerId==2))
		{
			return new Post(1, "hello this is a test", 2, 1);
		}
		else
		{
			return null;
		}
	}

	public void createNewData(){}

	public UIThread createNewThread(final String topic,final long userId){
		return new Thread(1,topic);
	}

	public boolean deletePost(final long userId, final long postId, final long threadId){
		if ((userId== -1) || (postId== -1) || (threadId== -1))
		{
			return false;
		}
		else
		{
			return true;
		}

	}

	/**
	 * @param username - the username of the person who wants to login
	 * @param password - the password of the person who wants to login
	 * @return true if succsseful of false otherwise
	 */
	@Override
	public boolean login(final String username, final String password) {

		if ((username.equals("dani"))&&(password.equals("2222")))
		{
			return false;
		}
		if ((username.equals("dani"))&&(password.equals("5555")))
		{
			return false;
		}

		if ((username.equals("yosi"))&&(password.equals("2222")))
		{
			return true;
		}
		if ((username.equals("dani"))&&(password.equals("1234")))
		{
			return true;
		}
		return false;
	}

	public boolean logout(final long userId){
		if ((userId==-1) || (userId==3))
		{
			return false;
		}
		else
		{
			return true;
		}
	}

	/**
	 * @param username - the username of the person who wants to register
	 * @param password - the password of the person who wants to register
	 * @return true if succsseful of false otherwise
	 */
	@Override
	public boolean register(final String username, final String password) {
		if ((username.equals(""))||(password.equals("") ))
		{
			return false;
		}
		else
		{
			if (username.equals("r eut"))
			{
				return false;
			}
			else
				if (password.equals("12 3"))
				{
					return false;
				}
		}
		if ((username.equals("moshe"))&&(password.equals("1111"))&& (!this.wasRegistered))
		{
			this.wasRegistered = true;
			return true;
		}
		if ((username.equals("moshe"))&&(password.equals("1111"))&& (this.wasRegistered))
		{
			return false;
		}
		if ((username.equals("dani"))&&(password.equals("1234")))
		{
			return (true);
		}
		if ((username.equals("yosi"))&&(password.equals("2222")))
		{
			return (true);
		}
		return false;
	}
	public boolean searchForMessageByCategories(final String authorName, final String msg){
		if ((authorName.equals("dani"))&& (msg.equals("hello this is a test message fron dani")))
		{
			return true;
		}
		else
		{
			return false;
		}
	}




}
